<template>
	<view class="container">
		<scroll-view scroll-y="true">
			<template>
				<view class="card-item" v-if="dynamicData">
					<view class="card-head">
						<image :src="dynamicData.avatar" mode="aspectFill" class="head-left"></image>
						<view class="head-right">
							{{dynamicData.username}}
							<view class="upload">
								{{formatTime(dynamicData.time)}}
							</view>
						</view>
					</view>
					<view class="card-content ">
						<view class=" content-txt">
							<label class="label">{{labelFn(dynamicData.label)}}</label>{{dynamicData.contentTxt}}
						</view>
						<view class="content-imgs">
							<template v-for="img in dynamicData.contentImg">
								<image :src="img" mode="aspectFit" class="content-img"></image>
							</template>
						</view>
					</view>
				</view>
			</template>
		</scroll-view>
	</view>
</template>

<script>
	import getDateDiff from '../../../util/timeFormat.js'
	import {
		getDynamicData
	} from '../../../database/index.js'
	export default {
		data() {
			return {
				dynamicData: ''
			}
		},

		methods: {
			labelFn(label) {
				switch (label) {
					case 0:
						return '运动记录'
					case 1:
						return '心情记录'
				}
			},
			formatTime(stamp) {
				setInterval(() => {
						this.formatTime(stamp)
					},
					60 * 1000)
				return getDateDiff(stamp);
			}
		},
		async onLoad(opt) {
			console.log(opt.id);
			let datas = await getDynamicData({
				_id: opt.id
			})
			this.dynamicData = datas[0]
		},
	}
</script>

<style lang="scss" scoped>
	$tabSize: 50rpx;

	.card-item {
		color: black;
		margin-bottom: 30rpx;
		background-color: white;
		padding: 20rpx;

		.card-content {
			margin-top: 30rpx;

			.content-txt {
				line-height: 1.6rem;

				.label {
					margin-right: 10rpx;
					padding: 10rpx 20rpx;
					font-size: 0.8rem;
					background-color: rgba(119, 136, 153, .2);
					color: #4682B4;
					font-weight: 600;
					border-radius: 10rpx;
				}
			}

			.content-imgs {
				margin-top: 10rpx;
				padding: 0;

				.content-img {
					border: 1px solid #e6e6e6;
					margin-bottom: 20rpx;
				}
			}
		}

	}

	.card-head {
		display: flex;
		flex-direction: row;

		.head-left {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			border: 5rpx solid #B0C4DE;
		}

		.head-right {
			flex: 1;
			position: relative;
			margin-left: 20rpx;
			font-size: 1.1rem;
			font-weight: 600;
			letter-spacing: 2rpx;

			.upload {
				letter-spacing: 0;
				font-weight: 100;
				font-size: 0.8rem;
				color: #afafaf;
				position: absolute;
				bottom: 0;
			}
		}
	}
</style>